package com.wnxy.admin.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.text.DateFormatSymbols;
import java.util.*;

/**
 * @author hj
 * 能耗报表dto
 */
@Data
@AllArgsConstructor
public class ChargingPileReportDto {

    private Long orderId;

    //"充电桩名称")
    private String chargingPileName;
    //充电站名称
    private String chargingStationName;
    //充电量
    private BigDecimal chargeAmount;
    //结束时间
    private Date endTime;

    //1月到12月充电量数据
    private Map<String,BigDecimal> monthReport;


    // Constructors, getters, setters, etc.

    public ChargingPileReportDto() {
        // 初始化12个月的monthReport map，使用英文单词表示月份
        DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
        String[] monthNames = symbols.getMonths();

        monthReport = new LinkedHashMap<>(); // 使用LinkedHashMap维护插入顺序
        for (int month = 1; month <= 12; month++) {
            monthReport.put(monthNames[month - 1], BigDecimal.ZERO);
        }
    }

    public void updateMonthReport() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(endTime);
        int month = calendar.get(Calendar.MONTH); // 月份在Calendar中是从零开始的

        // 用chargeAmount更新monthReport映射
        String monthName = new DateFormatSymbols(Locale.ENGLISH).getMonths()[month];
        monthReport.put(monthName, monthReport.get(monthName).add(chargeAmount));
    }
}
